package com.bj58.mis.apm.client.core.util;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

public class PropertiesBean {
    private Properties properties;
    public PropertiesBean(Properties properties){
        this.properties = properties;
    }

    public List<String> propertyNames() {
        List<String> propNamesList = new ArrayList<String>();
        Enumeration<String> propNamesEnum = (Enumeration<String>) this.properties.propertyNames();
        while(propNamesEnum.hasMoreElements()){
            String propName = propNamesEnum.nextElement();
            propNamesList.add(propName);
        }
        return propNamesList;
    }

    public String getValue(String key){
        return this.properties.getProperty(key);
    }
    public String getValue(String key, String defaultValue){
        return this.properties.getProperty(key, defaultValue);
    }

    public boolean getBooleanValue(String key){
        return getBooleanValue(key, false);
    }
    public boolean getBooleanValue(String key, boolean defaultValue){
        String value = getValue(key);
        return value!=null ? "true".equals(value.trim().toLowerCase()) : defaultValue;
    }

    public Long getLongValue(String key){
        String value = getValue(key);
        return value!=null ? Long.parseLong(value) : null;
    }
    public Long getLongValue(String key, long defaultValue){
        String value = getValue(key);
        return value!=null ? Long.parseLong(value) : defaultValue;
    }
}
